package com.ruoyi.web.controller.ydz;

import java.util.List;

import com.ruoyi.web.domain.OldQuestion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Question;
import com.ruoyi.web.service.IQuestionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问答管理（新）Controller
 *
 * @author drx
 * @date 2024-03-18
 */
@Controller
@RequestMapping({"/ydz/question", "/api/question"})
@Api(tags = "问答管理（新）")
public class QuestionController extends BaseController {
    private String prefix = "ydz/question";

    @Autowired
    private IQuestionService questionService;

    @RequiresPermissions("ydz:question:view")
    @GetMapping()
    public String question() {
        return prefix + "/question";
    }
    @GetMapping("/push/qianfan")
    public String baiduIndex(){
        return "ydz/push/qianfan/qianfan";
    }

    @GetMapping("/push/qianfan/add")
    public String baiduAdd(){
        return "ydz/push/qianfan/add";
    }
    /**
     * 查询问答管理（新）列表
     */
    @RequiresPermissions("ydz:question:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询问答管理（新）列表")
    public TableDataInfo list(Question question) {
        startPage();
        List<Question> list = questionService.selectQuestionList(question);
        return getDataTable(list);
    }

    @PostMapping("/selectQuestionList")
    @ResponseBody
    @ApiOperation("查询问答管理（新）列表")
    public TableDataInfo selectQuestionList(@RequestBody Question question) {
        startPage();
        List<Question> list = questionService.selectQuestionList(question);
        return getDataTable(list);
    }

    /**
     * 导出问答管理（新）列表
     */
    @RequiresPermissions("ydz:question:export")
    @Log(title = "问答管理（新）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出问答管理（新）列表")
    public AjaxResult export(Question question) {
        List<Question> list = questionService.selectQuestionList(question);
        ExcelUtil<Question> util = new ExcelUtil<Question>(Question.class);
        return util.exportExcel(list, "问答管理（新）数据");
    }

    /**
     * 新增问答管理（新）
     */
    @GetMapping("/add")
    @ApiOperation("新增问答管理（新）")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存问答管理（新）
     */
    @ApiOperation("新增保存问答管理（新）")
    @RequiresPermissions("ydz:question:add")
    @Log(title = "问答管理（新）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Question question) {
        return toAjax(questionService.insertQuestion(question));
    }

    /**
     * 修改问答管理（新）
     */
    @ApiOperation("修改问答管理（新）")
    @RequiresPermissions("ydz:question:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Question question = questionService.selectQuestionById(id);
        mmap.put("question", question);
        return prefix + "/edit";
    }

    /**
     * 修改保存问答管理（新）
     */
    @ApiOperation("修改保存问答管理（新）")
    @RequiresPermissions("ydz:question:edit")
    @Log(title = "问答管理（新）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Question question) {
        return toAjax(questionService.updateQuestion(question));
    }

    /**
     * 删除问答管理（新）
     */
    @ApiOperation("删除问答管理（新）")
    @RequiresPermissions("ydz:question:remove")
    @Log(title = "问答管理（新）", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(questionService.deleteQuestionByIds(ids));
    }

    /**
     * 修改保存问题管理（旧）
     */
    @ApiOperation("修改保存问题管理（新）")
    @RequiresPermissions("ydz:question:edit")
    @Log(title = "药品管理（旧）", businessType = BusinessType.UPDATE)
    @PostMapping("/editState")
    @ResponseBody
    public AjaxResult editState(@RequestBody Question question) {
        return toAjax(questionService.updateQuestion(question));
    }

    /**
     * 获取问题详情-前端调用
     */
    @ApiOperation("获取问题详情-前端调用")
    @GetMapping("/get/{id}")
    @ResponseBody
    public AjaxResult get(@PathVariable("id") Long id) {
        return questionService.getQuestionById(id);
    }

    /*
     * 根据新闻id查询上一篇下一篇
     * */
    @GetMapping("/getUpandDown/{id}")
    @ResponseBody
    public AjaxResult getUpandDown(@PathVariable("id") Long id) {
        return questionService.getUpandDown(id);
    }

    /**
     * 获取首页-药品知识
     */
    @ApiOperation("获取首页-药品问答")
    @GetMapping("/getQuestionListView")
    @ResponseBody
    public AjaxResult getQuestionListView() {
        return questionService.getQuestionListView();
    }

    /*
     * 增加浏览量
     * */
    @GetMapping("/updateQuesBrowseNum/{id}")
    @ResponseBody
    public void updateQuesBrowseNum(@PathVariable("id") Long id) {
        questionService.updateQuesBrowseNum(id);
    }

    @RequestMapping("/addQustionByAi")
    @ResponseBody
    public AjaxResult addQustionByAi(@RequestBody Question question){
        return questionService.addQustionByAi(question);
    }
}
